/*
 * TODO
 */
package com.xtrip.net.response;

import java.util.ArrayList;
import java.util.List;

import org.dom4j.Element;

import com.xtrip.adm.model.Area;
import com.xtrip.common.BasicConstant;
import com.xtrip.util.IdGenerator;
import com.xtrip.util.parse.xml.XtripDocumentHelper;

/**
 * @project xtrip
 * @author shiming.yao
 * @time 2013-5-31
 */
public class TcAreaRsp extends TcBaseResponse {

	private List<Area> list = null;
	private int totalCount = 0;
	/* (non-Javadoc)
	 * @see com.xtrip.net.request.TcBaseResponse#parseBody(org.dom4j.Element)
	 */
	@Override
	protected void parseBody(Element body) {
		// TODO Auto-generated method stub
		Element countyListEl = body.element("countyList");
		String totCountStr = XtripDocumentHelper.getNodeAttrVal(countyListEl, "totalCount");
		if(totCountStr != null){
			setTotalCount(Integer.parseInt(totCountStr));
		}
		List<Element> countys = countyListEl.elements("county");
		List<Area> clist = new ArrayList<Area>();
		for(Element county : countys){
			List<Element> elist = county.elements();
			Area a = new Area();
			a.setId(IdGenerator.generateId(BasicConstant.PREFIX_AREA));
			for(Element item : elist){
				String name = item.getName();
				String value = item.getStringValue();
				if(name.equals("id")){
					a.setTcAId(value);
				} else if(name.equals("name")){
					a.setName(value);
				} else if(name.equals("prefixLetter")){
					a.setIndex(value);
				} else if(name.equals("enName")){
					a.seteName(value);
				}
			}
			clist.add(a);
		}
		setList(clist);
	}
	public List<Area> getList() {
		return list;
	}
	public void setList(List<Area> list) {
		this.list = list;
	}
	public int getTotalCount() {
		return totalCount;
	}
	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}
	public class Tccounty {
		private String name;
		private String id;
		private String index;
		private String enName;
		
		public String getName() {
			return name;
		}
		public void setName(String name) {
			this.name = name;
		}
		public String getId() {
			return id;
		}
		public void setId(String id) {
			this.id = id;
		}
		public String getIndex() {
			return index;
		}
		public void setIndex(String index) {
			this.index = index;
		}
		public String getEnName() {
			return enName;
		}
		public void setEnName(String enName) {
			this.enName = enName;
		}
	}

}
